<template>
    <view class="card-list">
        <view
            v-for="(card, index) in cards"
            :key="index"
            :class="['card', { 'past': isPastDeadline(card.deadline) }]"
            :style="{ backgroundImage: `url(${card.backgroundImage})` }"
            @click="navigateToDetail(card.catId, card.id)"
        >
            <view class="content">
                <view class="header">
                    <view class="title">{{ card.title }}</view>
                    <view class="date" :class="{ 'past': isPastDeadline(card.deadline) }">
                        {{ card.date }}<span>日</span>
                    </view>
                </view>
                <view class="body">
                    <view class="text">{{ card.text }}</view>
                    <button class="signup-button" @click.stop="signup(card.catId, card.id)" :class="{ 'past': isPastDeadline(card.deadline) }">报名</button>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    name: "HealthTipCardList",
    props: {
        cards: {
            type: Array,
            default: () => []
        }
    },
    methods: {
        navigateToDetail(catId, id) {
            this.$tab.navigateTo(`/pages/mine/info/index?catId=${catId}&id=${id}`);
        },
        signup(catId, id) {
            this.$tab.navigateTo(`/pages/vist/audi?catId=${catId}&id=${id}`);
        },
        isPastDeadline(deadlineTimestamp) {
            return deadlineTimestamp < Date.now(); // 判断截止时间是否已过
        } 
    }
};
</script>

<style scoped>
.card-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
    background-color: #f0fff0;
}

.card {
    position: relative;
    width: calc(100% - 40px);
    max-width: 600px;
    margin: 20px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    border: 1px solid #ccc;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
}

.content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    color: #fff;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.title {
    font-size: 28rpx;
    font-weight: bold;
    padding: 8px 16px;
    background-color: #b8860b;
    border-top-right-radius: 8px;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    align-self: flex-start;
    position: relative;
    margin-left: -20px;
}

.title::after {
    content: "";
    position: absolute;
    top: -10px;
    right: 0;
    border-width: 10px 0 0 10px;
    border-color: transparent transparent transparent rgba(0, 0, 0, 0.4);
    border-style: solid;
}

.date {
    font-size: 20px;
    text-align: right;
    background-color: #39b54a;
    color: #fff;
    padding: 46px 32px 5px 39px;
    border-bottom-left-radius: 8px;
    border-top-right-radius: 8px;
    position: absolute;
    top: 0;
    right: -50px;
    margin: 8px 13px 6px 22px;
    transform: translateY(-50%) rotate(45deg);
    transform-origin: center center;
    z-index: 1;
    line-height: 10px;
}

.date span {
    font-size: 20rpx;
    margin-left: 5rpx;
}

.body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.text {
    font-size: 24rpx;
    flex: 1;
    color: #fff;
}

.signup-button {
    margin-left: 10px;
    padding: 8px 16px;
    background-color: #39b54a;
    color: #fff;
    text-align: center;
    border: none;
    border-radius: 8px;
    font-size: 20rpx;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.signup-button:hover {
    background-color: #33a142;
}

.past {
    filter: grayscale(100%);
    cursor: not-allowed;
    pointer-events: none;
}

.past .signup-button {
    background-color: #ccc;
    cursor: not-allowed;
}

.past .date {
    background-color: #999;
}
</style>
